using System.Windows;

namespace GraphMyCode.Controls
{
	public static class RectExtensions
	{
		public static bool IntersectsWith(this Rect rect1, Rect rect2)
		{
			if (rect1.IsEmpty || rect2.IsEmpty)
			{
				return false;
			}
			return ((((rect2.Left <= rect1.Right) && (rect2.Right >= rect1.Left)) && (rect2.Top <= rect1.Bottom)) && (rect2.Bottom >= rect1.Top));
		}

		public static Rect Scale(this Rect rect1, double scaleX, double scaleY)
		{
			if (!rect1.IsEmpty)
			{
				rect1.X *= scaleX;
				rect1.Y *= scaleY;
				rect1.Width *= scaleX;
				rect1.Height *= scaleY;
				if (scaleX < 0.0)
				{
					rect1.X += rect1.Width;
					rect1.Width *= -1.0;
				}
				if (scaleY < 0.0)
				{
					rect1.Y += rect1.Height;
					rect1.Height *= -1.0;
				}
			}
			return rect1;
		}
	}
}